package com.user.web.action;

import com.opensymphony.xwork2.ActionSupport;
import com.user.domain.User;
import com.user.service.Page;
import com.user.service.SortHelper;
import com.user.service.UserQryHelper;
import com.user.service.UserService;

public class UserAction extends ActionSupport {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private UserService userService;
	private User user;
	Page page = new Page();
	
	private UserQryHelper helper = new UserQryHelper(new SortHelper("userId"));//排序默认id
	
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public Page getPage() {
		return page;
	}
	public void setPage(Page page) {
		this.page = page;
	}
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	public UserQryHelper getHelper() {
		return helper;
	}
	public void setHelper(UserQryHelper helper) {
		this.helper = helper;
	}
	
	/**
	 * 创建用户
	 * @return
	 */
	public String create()
	{
		userService.createUser(user);
		return "loadAll";
	}
	/**
	 * 进入主页面
	 * @return
	 */
	public String login()
	{
		return LOGIN;
	}
	/**
	 * 根据id获取用户
	 * @return  修改视图
	 */
	public String preModify()
	{
		user = userService.getUserById(user.getUserId());
		return "editview";
	}
	/**
	 * 更新用户信息
	 * @return 用户列表
	 */
	public String modify()
	{
		userService.modifyUser(user);
		return "loadAll";
	}
	/**
	 * 注销用户
	 * @return 用户列表
	 */
	public String remove()
	{
		userService.removeUser(user);
		return "loadAll";
	}
	/**
	 * 用户列表
	 * @return
	 */
	public String list()
	{
		page = userService.loadAll(page, helper);
		return "listview";
	}


}
